
use "${data}IndirectSurveyDataReplication.dta", clear

********************************************************************************************************
************ VARIATION IN CORRELATION BETWEEN LEADER AND HOUSEHOLD
************ REPORTS OF SAME VARIABLE INTERACTED WITH RESPONSE NUMBER     	*************
********************************************************************************************************

estimates clear
xtset ejnclnmid
foreach x in tel_movil jefe_secondaria personas_hogar paredes_vivienda  television   coche num_ganado_mayor cuidado_bosque     {
preserve
rename `x'_hh_a x1
reg `x'_a x1, cluster(ejnclnmid) 
estimates store `x'_1
xtreg `x'_a x1 , fe i(ejnclnmid)
estimates store `x'_2
xi: reg `x'_a  i.orden_entrevista*x1, cluster(ejnclnmid) 
estimates store `x'_3
xi: xtreg `x'_a i.orden_entrevista*x1, fe i(ejnclnmid)
estimates store `x'_4
restore
}

************ FORMAT TABLE **************************
esttab *_1  ///
	using "${outputs}corr_variables.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "") ///
	  nonumbers  replace  fragment  keep(x1) ///
	  coeflabels(x1 "Household report") ///
	 prehead({ \begin{tabular}{lcccccccc}    ///
	 \hline \hline ///
	 & Cell & Secondary & HH size & Wall & TV & Car & \# & Forest  \\ ///
	 & phone & school & & type & & & livestock & work \\ ///
	 & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\   ) ///
	 posthead(\hline\multicolumn{9}{l}{\emph{ A: Simple correlations}} \\ )

esttab *_3  ///
	using "${outputs}corr_variables_order.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" ""  "" "" "" "" "" ) ///
	 nonumbers  replace  fragment keep( x1  _IordXx1_2 _IordXx1_3 ) ///
	 coeflabels(x1 "Household report" _IordXx1_2 "Second household" _IordXx1_3 "Third household") ///
	  prehead({ \begin{tabular}{lcccccccc}    ///
	 \hline \hline ///
	 & Cell & Secondary & HH size & Wall & TV & Car & \# & Forest  \\ ///
	 & phone & school & & type & & & livestock & work \\ ///
	 & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\   ) ///
	 posthead(\hline\multicolumn{9}{l}{\emph{ A: OLS with household order}} \\ )
	 
esttab *_2  ///
	using "${outputs}corr_variables.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" ""  "" "" "" "" "" ) ///
	 nonumbers  append  fragment keep(x1) ///
	  coeflabels(x1 "Household report") ///
	 posthead(\hline  \multicolumn{9}{l}{\emph{B: Ejido FE}} \\ ) ///
	  prefoot( \\ ) ///
	  postfoot(\hline \hline \end{tabular} } \begin{tablenotes}[para,flushleft] \footnotesize{Each panel represents a different estimation. Dependent variables are leader reports, and household report indicates the household response for the same variable. Standard errors are clustered at the ejido level.* p $<$.10, ** p$<$ .05, *** p$<$.01.} \end{tablenotes} )	 
 

esttab *_4  ///
	using "${outputs}corr_variables_order.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ) ///
	  nonumbers  append  keep( x1  _IordXx1_2 _IordXx1_3 ) ///
	  coeflabels(x1 "Household report" _IordXx1_2 "Second household" _IordXx1_3 "Third household") ///
	 prehead( ) ///
	   posthead(\hline  \multicolumn{9}{l}{\emph{B: Ejido FE with household older}} \\ )  ///
	  prefoot( \\ ) ///
	  postfoot(\hline \hline \end{tabular} } \begin{tablenotes}[para,flushleft] \footnotesize{Each panel represents a different estimation. Dependent variables are leader reports, and household report indicates the household response for the same variable.  Second and third household indicates the interaction between the household reported variable and the order of questioning. Therefore, second household measures the difference in correlation between the leader and the household report for the second household relative to the first one. Standard errors are clustered at the ejido level.* p $<$.10, ** p$<$ .05, *** p$<$.01.} \end{tablenotes} )	 

estimates clear


foreach x in PIB IPW PCA {
egen `x'sd = sd(`x'_leader)
egen `x'mu = mean(`x'_leader)
gen z`x'_leader = (`x'_leader-`x'mu)/`x'sd
drop *sd *mu
egen `x'sd = sd(`x'_HH)
egen `x'mu = mean(`x'_HH)
gen z`x'_HH = (`x'_HH-`x'mu)/`x'sd
preserve
rename z`x'_HH x1

	
xi: reg z`x'_leader  x1, cluster(ejnclnmid) 
estimates store `x'_1
xi: xtreg z`x'_leader x1, fe i(ejnclnmid)
estimates store `x'_2
xi: reg z`x'_leader i.orden_entrevista*x1, cluster(ejnclnmid) 
estimates store `x'_3
xi: xtreg z`x'_leader i.orden_entrevista*x1, fe i(ejnclnmid)
estimates store `x'_4

restore
}


************ FORMAT TABLE **************************
esttab *_1  ///
	using "${outputs}corr_index.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" ) ///
	  nonumbers  replace  fragment  keep(x1) ///
	  coeflabels(x1 "Household report") ///
	 prehead({ \begin{tabular}{lccc}    ///
	 \hline \hline ///
	 & PIB & IPW & PCA  \\ ///
	 & (1) & (2) & (3) \\   ) ///
	 posthead(\hline\multicolumn{4}{l}{\emph{ A: Simple correlations}} \\ )

esttab *_2  ///
	using "${outputs}corr_index.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" ""  ) ///
	 nonumbers  append  fragment keep(x1) ///
	  coeflabels(x1 "Household index") ///
	 posthead(\hline  \multicolumn{4}{l}{\emph{B: Ejido FE}} \\ ) ///
	 prefoot( \\ ) ///
	  postfoot(\hline \hline \end{tabular} } \begin{tablenotes}[para,flushleft] \footnotesize{Each panel represents a different estimation. Dependent variables are leader indices, and household index indicates the index constructed from the household responses for the same variable.   Standard errors are clustered at the ejido level.* p $<$.10, ** p$<$ .05, *** p$<$.01.} \end{tablenotes} )	 
	 
esttab *_3  ///
	using "${outputs}corr_index_order.tex", replace ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" ) ///
	 nonumbers   fragment keep( x1  _IordXx1_2 _IordXx1_3 ) ///
	 coeflabels(x1 "Household index" _IordXx1_2 "Second household" _IordXx1_3 "Third household") ///
	 prehead({ \begin{tabular}{lccc}    ///
	 \hline \hline ///
	 & PIB & IPW & PCA  \\ ///
	 & (1) & (2) & (3) \\   ) ///
	 posthead(\hline \multicolumn{4}{l}{\emph{A: OLS with household order}} \\ ) 

 esttab *_4  ///
	using "${outputs}corr_index_order.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" ) ///
	  nonumbers  append  keep( x1  _IordXx1_2 _IordXx1_3 ) ///
	  coeflabels(x1 "Household index" _IordXx1_2 "Second household" _IordXx1_3 "Third household") ///
	 prehead( ) ///
	   posthead(\hline  \multicolumn{4}{l}{\emph{B: Ejido FE with household older}} \\ )  ///
	  prefoot( \\ ) ///
	  postfoot(\hline \hline \end{tabular} } \begin{tablenotes}[para,flushleft] \footnotesize{Each panel represents a different estimation. Dependent variables are leader indices, and household index indicates the index constructed from the household responses for the same variable.  Second and third household indicates the interaction between the household reported index and the order of questioning. Therefore, second household measures the difference in correlation between the leader and the household index for the second household relative to the first one. Standard errors are clustered at the ejido level.* p $<$.10, ** p$<$ .05, *** p$<$.01.} \end{tablenotes} )	 

estimates clear
